define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'authuser/index',
                    add_url: 'authuser/add',
                    edit_url: 'authuser/edit',
                    reset_url: 'authuser/reset',
                    del_url: 'authuser/del',
                    multi_url: 'authuser/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'auth_user.id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'company', title: '公司名称',operate: 'LIKE'},
                        {field: 'appKey', title: 'appKey(商户号)',operate: 'LIKE'},
                        {field: 'appSecret', title: 'appSecret(秘钥)',operate: 'LIKE'},
                        {field: 'contact', title: '联系人',operate: 'LIKE'},
                        {field: 'mobile', title: '手机号',operate: 'LIKE'},
                        {field: 'addr', title: '地址',operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'),
                            table: table,
                            buttons :[
                                {name: 'reset', text: '重置秘钥', title: '重置秘钥',  classname: 'btn btn-xs btn-primary btn-ajax', url: 'authuser/reset',refresh:true}

                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        reset: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});